from typing import List


class Solution:
    def totalHammingDistance(self, nums: List[int]) -> int:
        ans, n = 0, len(nums)
        for i in range(30):
            counter = 0  # 计数器
            for num in nums:
                counter += (num >> i) & 1  # 取出第i位
            ans += counter * (n - counter)
        return ans


if __name__ == '__main__':
    sol = Solution()
    print(sol.totalHammingDistance([4, 14, 2]))
